//
//  QJBaseViewController.m
//  QJProject
//
//  Created by 高中雷 on 15/5/19.
//  Copyright (c) 2015年 高中雷. All rights reserved.
//

#import "QJBaseViewController.h"

@interface QJBaseViewController ()

{
    UIImageView * imageview;
    UIButton * backButton;
}
@end

@implementation QJBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
     self.automaticallyAdjustsScrollViewInsets = NO;

    self.b_navHeaderView = YES;
    if(self.tableView){
        m_tableView = [[QJUIMapping mapping] tableControlWithTableView:self.tableView withDelegate:self withContainer:self];
    }
    
}

-(NSMutableArray*)cellArray {
    if (!_cellArray) {
        _cellArray = [NSMutableArray array];
    }
    return _cellArray;
}
-(NSArray*)sortDatas {
    if (self.cellArray)
        return [NSArray arrayWithArray:self.cellArray];
    return @[];
}

-(void)reloadDatas {

        [m_tableView reload:[self sortDatas] withRowAnimation:UITableViewRowAnimationNone];

}

-(UIViewController*)getRootController {
    QJBaseViewController * clientController = self;
    
    while (clientController) {
        QJBaseViewController *client = NULL;
        
        if ([clientController isKindOfClass:[QJBaseViewController class]]) {
            client = (QJBaseViewController*)clientController.parentController;
        }
        
        if (!client && (clientController.navigationController || clientController.myNav)) {
            UINavigationController *nav = clientController.navigationController ? clientController.navigationController : clientController.myNav;
            
            client = [nav.viewControllers objectAtIndex:0];
            
            if ([client isKindOfClass:[QJBaseViewController class]]) {
                client = (QJBaseViewController*)client.parentController;
            }
            else {
                client = NULL;
            }
        }
        
        if (client) {
            clientController = client;
        }
        else
            break;
    }
    return clientController;
}




-(UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.sectionIndexBackgroundColor = [UIColor clearColor];
         _tableView.sectionIndexColor = [UIColor clearColor];
    }
    return _tableView;
}


-(void)initDataWithControl:(QJTableView*)control{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
